package com.hackordie.commons.authorities;

import java.util.Calendar;
import java.util.Date;

import com.hackordie.commons.game.player.UserComponent;
import com.hackordie.commons.hardware.components.AComponent;

public class User extends AEntity {

	private String userName;
	private String userPassword;
	private String email;
	private Date signinDate;
	private int  role;
	private String roleName;
	private boolean enabled;
	private String activationCode;
	private int computerType;
	
	//datos propios del juego
	private int money;  //dinero que posee
	private UserComponent[] bag;    //mooooochila-moooochila

	public User() {
		super();
	}

	public User(String userName, String userPassword, String email, int money, int computerType) {
		super();
		this.userName = userName;
		this.userPassword = userPassword;
		this.email = email;
		this.signinDate = Calendar.getInstance().getTime();
		this.enabled = false;
		this.activationCode = "1";
		this.role = -1;
		this.roleName = "";
		this.money = money;
		this.bag = null;
		this.computerType = computerType;
	}
	
	public User(String userName, String userPassword, String email, int role, int money, int computerType) {
        super();
        this.userName = userName;
        this.userPassword = userPassword;
        this.email = email;
        this.signinDate = Calendar.getInstance().getTime();
        this.enabled = false;
        this.activationCode = "1";
        this.role = role;
        this.roleName = "";
        this.money = money;
        this.bag = null;
        computerType = 1;
        this.computerType = computerType;
    }
	
	public User(int id, String userName, String userPassword, String email, int role, int money, int computerType) {
        super(id);
        this.userName = userName;
        this.userPassword = userPassword;
        this.email = email;
        this.signinDate = Calendar.getInstance().getTime();
        this.enabled = false;
        this.activationCode = "1";
        this.role = role;
        this.roleName = "";
        this.money = money;
        this.bag = null;
        computerType = 1;
        this.computerType = computerType;
    }
			
    public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getUserPassword() {
		return userPassword;
	}

	public void setUserPassword(String userPassword) {
		this.userPassword = userPassword;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public Date getSigninDate() {
		return signinDate;
	}

	public void setSigninDate(Date signinDate) {
		this.signinDate = signinDate;
	}

	public boolean isEnabled() {
		return enabled;
	}

	public void setEnabled(boolean enabled) {
		this.enabled = enabled;
	}

	public String getActivationCode() {
		return activationCode;
	}

	public void setActivationCode(String activationCode) {
		this.activationCode = activationCode;
	}
		
	public int getRole() {
        return role;
    }

    public void setRole(int role) {
        this.role = role;
    }
    
    public String getRoleName() {
        return roleName;
    }

    public void setRoleName(String roleName) {       
    this.roleName = roleName;            
    } 
        
    public int getMoney() {
        return money;
    }

    public void setMoney(int money) {
        this.money = money;
    }
        
    public UserComponent[] getBag() {
        return bag;
    }
    
    public void setBag(UserComponent[] userComponents) {
        bag = userComponents;
    }
    
        
    public int getComputerType() {
        return computerType;
    }

    public void setComputerType(int computerType) {
        this.computerType = computerType;
    }

    public UserComponent getComponentByName(String name) {        
        int pos = 0;
        boolean found = false;
        
        while(pos < bag.length && !found) {
            AComponent component = bag[pos].getComponent();
            
            if((component != null) && (component.getComponentName().equals(name)) ) {
                return bag[pos];
            }            
            pos++;
        }        
        return null;
    }
    
    public Object[] toArray() {
		return new Object[] { id, userName, userPassword, email, signinDate, enabled, activationCode, roleName, money };
	}
}
